function mySolution () {
	async function asyncFunc() {
		await new Promise((resolve) => {
			setTimeout(() => {
				resolve({msg:"异步任务处理结束"});
			}, 1000);
		})
	}
	
	function sync(func) {
		let cache = null;
		return function(){
			if (cache) {
				if (cache.status === 'fulfilled') {
					return cache;
				} else if (cache.status === 'rejected') {
					throw cache.err;
				}
				return cache;
			}
			const result = {
				status: "pending",
				data: null,
				err: null,
			}
			cache = result;
			
			throw func().then(res => {
				result.status = "fulfilled";
				result.data = res;
			}, err => {
				result.status = "reject";
				result.data = err;
			});
		}
	}
	asyncFunc = sync(asyncFunc);
	function main() {
		
		try {
			asyncFunc();
		} catch (err) {
			if (err instanceof Promise) {
				err.then(() => {
					asyncFunc()
				}, () => {
					asyncFunc()
				});
			}
		}
		console.log("异步函数执行完毕");
	}
	main();
	
	
}

function duyi(){
	function mockFetch () {
		return new Promise(resolve => {
			setTimeout(() => {
				resolve({msg:"请求成功"});
			}, 10000);
		})
	}
	function m3 () {
		return mockFetch();
	} 
	function main(){
		console.log("调用main");
		const user = m3();
		console.log(user);
	}
	function run(func) {
		console.log("调用run");
		let cache = [];
		let i = 0;
		const oldFetch = mockFetch;
		mockFetch = () => {
			if (cache[i]) {
				if (cache[i].status === 'fulfilled') {
					return cache[i].data;
				} else if (cache[i].status === 'rejected') {
					throw cache[i].err;
				}
			}
			const result = {
				status: 'pending',
				data: null,
				err: null,
			}
			cache[i++] = result;
			const prom = oldFetch().then(res => {
				result.status = 'fulfilled';
				result.data = res;
			});
			throw prom;
		}
		try {
			func();	
		}catch (err) {
			if (err instanceof Promise) {
				err.then(() => {
					i = 0;
					func();
				})
			}
		}
	}
	run(main);
	console.log("end");
}
duyi();